<template>
  <el-dialog title="售后明细" v-model="visible" width="800px" :close-on-click-modal="false" :close-on-press-escape="false">
    <ul class="history">
      <li v-for="item in list" :key="item.backHistoryId">
        <div class="history_progress" v-if="item.historyType === 'BACK_APPLY'">
          <div class="info">
            <p class="title">买家申请售后</p>
            <span class="time">{{ $formater.formatTime(item.createTime) }}</span>
          </div>
          <p class="text"><span class="text-title">售后类型：</span>退货退款</p>
          <p class="text"><span class="text-title">申请原因：</span>{{ item.historyVal.applyReason }}</p>
        </div>
        <div class="history_progress" v-if="item.historyType === 'AGREE_BACK'">
          <div class="info">
            <p class="title">卖家同意售后</p>
            <span class="time">{{ $formater.formatTime(item.createTime) }}</span>
          </div>
        </div>

        <div class="history_progress" v-if="item.historyType === 'DELIVERED'">
          <div class="info">
            <p class="title">买家退回商品</p>
            <span class="time">{{ $formater.formatTime(item.createTime) }}</span>
          </div>
          <p class="text"><span class="text-title">物流单号:</span>{{ item.historyVal.trackingNumber }}</p>
        </div>

        <div class="history_progress" v-if="item.historyType === 'RECEIVED'">
          <div class="info">
            <p class="title">卖家确认收货</p>
            <span class="time">{{ $formater.formatTime(item.createTime) }}</span>
          </div>
        </div>

        <div class="history_progress" v-if="item.historyType === 'REFUND'">
          <div class="info">
            <p class="title">卖家退款</p>
            <span class="time">{{ $formater.formatTime(item.createTime) }}</span>
          </div>
          <div class="text">
            <span class="text-title">退款凭证 </span>
            <el-image class="qualica" v-for="(backPayProof, index) in item.historyVal.backPayProof?.split(',')" :key="index" :src="backPayProof" :preview-src-list="[backPayProof]"> </el-image>
          </div>
        </div>

        <div class="history_progress" v-if="item.historyType === 'CONFIRM_RECEIPT'">
          <div class="info">
            <p class="title">买家确认收款</p>
            <span class="time">{{ $formater.formatTime(item.createTime) }}</span>
          </div>
          <p class="text">售后完成</p>
        </div>

        <div class="history_progress" v-if="item.historyType === 'REFUSE_BACK'">
          <div class="info">
            <p class="title">卖家拒绝售后</p>
            <span class="time">{{ $formater.formatTime(item.createTime) }}</span>
          </div>
          <p class="text"><span class="text-title">拒绝原因:</span>{{ item.historyVal.remark }}</p>
        </div>
      </li>
    </ul>
  </el-dialog>
</template>

<script setup>
import { computed } from 'vue'
import formater from '@/formater'

const emit = defineEmits(['update:visible'])
const props = defineProps(['visible', 'list'])

const visible = computed({
  get: () => {
    return props.visible
  },
  set: (value) => emit('update:visible', value)
})
</script>

<style scoped lang="scss">
.history {
  padding: 0 30px 30px;
  height: 300px;
  overflow-y: auto;

  li {
    .history_progress {
      position: relative;
      padding-left: 20px;
      line-height: 20px;
      color: var(--color-text);
      border-bottom: 1px solid var(--border-color);
      padding: 10px 0 10px 20px;

      .info {
        display: flex;
        align-items: center;
        justify-content: space-between;

        .title {
          font-weight: 500;
        }
      }

      .text {
        margin-top: 10px;

        .text-title {
          margin-right: 10px;
        }

        .qualica {
          width: 76px;
          height: 76px;
          vertical-align: top;
          margin-left: 10px;
        }
      }
    }

    .history_progress::before {
      content: '';
      position: absolute;
      left: 0;
      top: 15px;
      width: 10px;
      height: 10px;
      background-color: #1989fa;
      border-radius: 50%;
    }
  }
}
</style>
